package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.model.dao.LpStoreTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpStoreTbl;
import cn.com.lsy.product.lepao.model.entities.LpStoreTblExample;
import cn.com.lsy.product.lepao.model.mt.dao.MtDataTotalMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtOrderFormMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtStoreDataTotalMapper;
import cn.com.lsy.product.lepao.model.mt.entities.IncomeDataChartsDto;
import cn.com.lsy.product.lepao.model.mt.entities.NewCardTotalDto;
import cn.com.lsy.product.lepao.service.IStatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StatisticalService implements IStatisticalService {

    @Autowired
    MtDataTotalMapper mtDataTotalMapper;
    @Autowired
    MtStoreDataTotalMapper mtStoreDataTotalMapper;
    @Autowired
    LpStoreTblMapper lpStoreTblMapper;
    @Autowired
    MtOrderFormMapper mtOrderFormMapper;

    @Override
    public List<IncomeDataChartsDto> selectPlatformIncome(int pageSize, String type, String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);
        where.put("type", type);
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtDataTotalMapper.selectPlatformIncome(where);
    }

    @Override
    public List<IncomeDataChartsDto> selectStoreIncome(int pageSize, String type, int storeId, String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);
        where.put("type", type);
        where.put("storeId", storeId);
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtStoreDataTotalMapper.selectStoreIncome(where);
    }

    @Override
    public List<IncomeDataChartsDto> selectPlatformEnter(int pageSize, String stringTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);
        where.put("stringTime", stringTime);
        where.put("endTime", endTime);

        return mtDataTotalMapper.selectPlatformEnter(where);
    }

    @Override
    public List<IncomeDataChartsDto> selectStoreEnter(int pageSize, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("pageSize", pageSize);
        where.put("storeId", storeId);

        return mtStoreDataTotalMapper.selectStoreEnter(where);
    }

    @Override
    public List<LpStoreTbl> selectStoreByNumber() {

        LpStoreTblExample example = new LpStoreTblExample();
        example.createCriteria().andStatusEqualTo(Constant.status.enable);
        example.setOrderByClause("online_sum desc");

        return lpStoreTblMapper.selectByExample(example);

    }

    @Override
    public String getStoreNumberState(int num) {

        return "1";
    }

    @Override
    public NewCardTotalDto selectPlatformMonthCardNum(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtOrderFormMapper.selectPlatformMonthCardNum(where);
    }

    @Override
    public int selectStoreMonthCardNum(String startTime, String endTime, String type, int storeId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("type", type);
        where.put("storeId", storeId);

        return mtOrderFormMapper.selectStoreMonthCardNum(where);
    }
}
